const API_BASE = '/api'

class ApiService {
  // 获取网站配置
  async getSettings() {
    const response = await fetch(`${API_BASE}/settings`)
    return await response.json()
  }

  // 更新网站配置
  async updateSettings(data) {
    const response = await fetch(`${API_BASE}/settings`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(data)
    })
    return await response.json()
  }

  // 获取关于页面内容
  async getAbout() {
    const response = await fetch(`${API_BASE}/about`)
    return await response.json()
  }

  // 更新关于页面内容
  async updateAbout(data) {
    const response = await fetch(`${API_BASE}/about`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(data)
    })
    return await response.json()
  }

  // 用户登录
  async login(credentials) {
    const response = await fetch(`${API_BASE}/auth/login`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(credentials)
    })
    return await response.json()
  }

  // 用户登出
  async logout() {
    const response = await fetch(`${API_BASE}/auth/logout`)
    return await response.json()
  }
}

export default new ApiService()
